package com.huangpuweb.api.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Charsets;
import com.huangpuweb.api.Constants;
import com.huangpuweb.api.model.*;
import com.huangpuweb.api.service.LaoXiMenApiService;
import com.huangpuweb.api.util.MapUtil;
import com.huangpuweb.api.util.StringUtil;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;


/**
 * 老西门店招店牌-隐患
 */
@Controller
@RequestMapping(value = "/laoximenapi")
public class LaoXiMenApiController {

    private static Logger logger = Logger.getLogger(LaoXiMenApiController.class);

    private LaoXiMenApiService laoXiMenApiService;


    @Autowired
    public void setLaoXiMenApiService(LaoXiMenApiService laoXiMenApiService) {
        this.laoXiMenApiService = laoXiMenApiService;
    }


    @RequestMapping(value = "/getHpDianZhaoDianPaiInfoStreetByspecification")
    public void getHpDianZhaoDianPaiInfoStreetByspecification(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);

        LogFactory.getLog(this.getClass()).info("------getHpDianZhaoDianPaiInfoStreetByspecification-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        String specification = reqjson.getString("specification");


        JSONArray jsonArray = new JSONArray();
        List<String> listSysShopSignageStreet = laoXiMenApiService.getListSysShopSignageStreetByspecification(specification);
        JSONObject jo = null;
        for (String s : listSysShopSignageStreet) {
            jo = new JSONObject();
            SysShopRecruitStreet ss = laoXiMenApiService.getLxmShopRecruitByNumber(s);
            jo.put("name", ss.getUnit_name());
            jo.put("id", ss.getId());
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getLng()), Double.parseDouble(ss.getLat()));
            jo.put("lng", map[0] + "");
            jo.put("lat", map[1] + "");

            jsonArray.add(jo);

        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 根据店铺类型获取数据
     */
    @RequestMapping(value = "/getHpDianZhaoDianPaiInfoStreetByXiaoType")
    public void getHpDianZhaoDianPaiInfoStreetByXiaoType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);

        LogFactory.getLog(this.getClass()).info("------getHpDianZhaoDianPaiInfoStreetByXiaoType-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        String type = reqjson.getString("type");

        List<SysShopRecruitStreet> listSysShopRecruitStreet = laoXiMenApiService.getListShopByXiaotype(type);

        for (SysShopRecruitStreet s : listSysShopRecruitStreet) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(s.getLng()), Double.parseDouble(s.getLat()));
            s.setLng(map[0] + "");
            s.setLat(map[1] + "");
        }


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listSysShopRecruitStreet);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 根据店铺类型获取数据
     */
    @RequestMapping(value = "/getHpDianZhaoDianPaiInfoStreetByType")
    public void getHpDianZhaoDianPaiInfoStreetByType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);

        LogFactory.getLog(this.getClass()).info("------getHpDianZhaoDianPaiInfoStreetByType-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        String type = reqjson.getString("type");

        List<SysShopRecruitStreet> listSysShopRecruitStreet = laoXiMenApiService.getListShopBytype(type);

        for (SysShopRecruitStreet s : listSysShopRecruitStreet) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(s.getLng()), Double.parseDouble(s.getLat()));
            s.setLng(map[0] + "");
            s.setLat(map[1] + "");
        }


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listSysShopRecruitStreet);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 获取全街道类型列表
     */
    @RequestMapping(value = "/getListTypeByStreet")
    public void getListTypeByStreet(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject returnjson = new JSONObject();
        Integer shopcount = laoXiMenApiService.getLxmShopCount();
        List<String> listRoad = laoXiMenApiService.getListType();
        JSONArray ja = new JSONArray();
        JSONObject jo = null;
        for (String type : listRoad) {

            jo = new JSONObject();
            jo.put("name", type);
            Integer count = laoXiMenApiService.getLxmShopCountByType(type);
            jo.put("count", count);
            ja.add(jo);

        }
        returnjson.put("array", ja);
        returnjson.put("shopcount", shopcount);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", returnjson);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 根据店铺名称模糊查询
     */
    @RequestMapping(value = "/getHpDianZhaoDianPaiInfoStreetByShopName")
    public void getHpDianZhaoDianPaiInfoStreetByShopName(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);

        LogFactory.getLog(this.getClass()).info("------getHpDianZhaoDianPaiInfoStreetByShopName-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        String shopname = reqjson.getString("shopname");

        SysShopRecruitStreet s = laoXiMenApiService.getSysShopRecruitStreetByShopName(shopname);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", s);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 根据道路名获取点铺列表
     */
    @RequestMapping(value = "/getHpDianZhaoDianPaiInfoStreetByRoadName")
    public void getHpDianZhaoDianPaiInfoStreetByRoadName(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);

        LogFactory.getLog(this.getClass()).info("------getHpDianZhaoDianPaiInfoStreetByRoadName-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        String roadname = reqjson.getString("roadname");

        List<SysShopRecruitStreet> listSysShopRecruitStreet = laoXiMenApiService.getListShopByRoadName(roadname);

        for (SysShopRecruitStreet s : listSysShopRecruitStreet) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(s.getLng()), Double.parseDouble(s.getLat()));
            s.setLng(map[0] + "");
            s.setLat(map[1] + "");
            s.setImageurl("http://172.82.4.51:8080/images/" + s.getSerial_number() + ".jpg");
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listSysShopRecruitStreet);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 获取全街道道路列表
     */
    @RequestMapping(value = "/getListRoadByStreet")
    public void getListRoadByStreet(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        List<String> listRoad = laoXiMenApiService.getListRoad();

        JSONObject returnjson = new JSONObject();
        Integer shopcount = laoXiMenApiService.getLxmShopCount();
        JSONArray ja = new JSONArray();
        JSONObject jo = null;
        for (String road : listRoad) {

            jo = new JSONObject();
            jo.put("name", road);
            Integer count = laoXiMenApiService.getLxmShopCountByRoad(road);
            jo.put("count", count);
            ja.add(jo);

        }
        returnjson.put("array", ja);
        returnjson.put("shopcount", shopcount);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", returnjson);
        responseData(resultObj.toString(), resp);


    }

    /**
     * 店招店牌分析
     */
    @RequestMapping(value = "/getOperateSignageData")
    public void getOperateSignageData(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        List<SysHpXiaoFangAjType> listSignageCount = laoXiMenApiService.getLxmShopSignage();
        Integer shopcount = laoXiMenApiService.getLxmShopCount();
        List<SysHpXiaoFangAjType> listShopCount = laoXiMenApiService.getLxmShopRecruitDzAffiliation();

        JSONObject jsonObject = null;
        for (SysHpXiaoFangAjType s : listShopCount) {
            jsonObject = new JSONObject();
            jsonObject.put("name", s.getName());
            double percent = (double) Integer.parseInt(s.getCount()) / shopcount;
            jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
            jsonArray.add(jsonObject);
        }

        JSONObject resultJson = new JSONObject();
        resultJson.put("jsonArray", jsonArray);
        resultJson.put("listSignageCount", listSignageCount);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 沿街店铺分析
     */
    @RequestMapping(value = "/getOperateShopData")
    public void getOperateShopData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        LogFactory.getLog(this.getClass()).info("------getOperateShopData-----start-------");
        Integer shopcount = laoXiMenApiService.getLxmShopCount();
        List<SysHpXiaoFangAjType> listTypeCount = laoXiMenApiService.getLxmShopTypeCount();
        JSONObject jsonObject = null;
        for (SysHpXiaoFangAjType s : listTypeCount) {
            jsonObject = new JSONObject();
            jsonObject.put("name", s.getName());
            double percent = Double.parseDouble(s.getCount()) / shopcount;
            jsonObject.put("percent", String.format("%.1f", percent * 100) + "%");
            jsonArray.add(jsonObject);
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 老西门街道店招店牌总览
     */
    @RequestMapping(value = "/getAllHpDianZhaoDianPaiData")
    public void getAllHpDianZhaoDianPaiData(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllHpDianZhaoDianPaiData-----start-------");

        //沿街店铺数
        Integer shopcount = laoXiMenApiService.getLxmShopCount();
        //店招店牌数
        Integer signagecount = laoXiMenApiService.getLxmShopSignageCount();

        //各类别数量
        List<SysHpXiaoFangAjType> listTypeCount = laoXiMenApiService.getLxmShopTypeCount();
        //监管力量
        List<LxmSuperviseStrength> listLxmSuperviseStrength = laoXiMenApiService.getListLxmSuperviseStrength();

        resultJson.put("shopcount", shopcount);
        resultJson.put("signagecount", signagecount);
        resultJson.put("listTypeCount", listTypeCount);
        resultJson.put("listLxmSuperviseStrength", listLxmSuperviseStrength);


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);
    }

    /**
         * 老西门电梯详情总览
     */
    @RequestMapping(value = "/getAllElevatorInfo")
    public void getAllElevatorInfo(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllElevatorInfo-----start-------");

        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getAliPersonDataByListTime-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String year = reqjson.getString("year");
        List<LxmElevatorInfo> elevatorInfoList;
        if (year!=null&&year.equals("2005")) {
            elevatorInfoList = laoXiMenApiService.getAllElevatorOldInfo(year);
        }else {
            //监管力量
          elevatorInfoList = laoXiMenApiService.getAllElevatorInfo();
        }
        for (LxmElevatorInfo ss : elevatorInfoList) {
            if (ss.getLat() != null && ss.getLat() != null) {
                double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getLng()), Double.parseDouble(ss.getLat()));
                ss.setLng(map[0] + "");
                ss.setLat(map[1] + "");
            }

            //处理字符串日期格式，注意数据库脏数据判断
            if (ss.getTest_date() != null && !ss.getTest_date().equals("")) {
                ss.setTest_date(ss.getTest_date().substring(0, 10));
            }
            if (ss.getNext_test_date() != null && !ss.getNext_test_date().equals("")) {
                ss.setNext_test_date(ss.getNext_test_date().substring(0, 10));
            }
            if (ss.getNext_selftest_date() != null && !ss.getNext_selftest_date().equals("")) {
                ss.setNext_selftest_date(ss.getNext_selftest_date().substring(0, 10));
            }
            if (ss.getDevice_stop_date() != null && !ss.getDevice_stop_date().equals("")) {
                ss.setDevice_stop_date(ss.getDevice_stop_date().substring(0, 10));
            }
            if (ss.getManufacture_date() != null && !ss.getManufacture_date().equals("")) {
                ss.setManufacture_date(ss.getManufacture_date().substring(0, 10));
            }
            if (ss.getPutuse_date() != null && !ss.getPutuse_date().equals("")) {
                ss.setPutuse_date(ss.getPutuse_date().substring(0, 10));
            }
        }
        resultJson.put("listLxmSuperviseStrength", elevatorInfoList);


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);

        return;
    }


    /**
     * 根据门店ID获取店招详情-老西门街道
     */
    @RequestMapping(value = "/getHpDianZhaoDianPaiInfoStreetByShopId")
    public void getHpDianZhaoDianPaiInfoStreetByShopId(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String str = getRequestBodyString(req);
        JSONObject jsonObject = null;

        LogFactory.getLog(this.getClass()).info("------getHpDianZhaoDianPaiInfoStreetByShopId-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        int shopid = reqjson.getInteger("shopid");

        SysShopRecruitStreet ss = laoXiMenApiService.getSysShopRecruitStreetByShopId(shopid);
        ss.setImageurl("http://172.82.4.51:8080/images/" + ss.getSerial_number() + ".jpg");
        ss.setImageurl1("http://172.82.4.51:8080/images/" + ss.getSerial_number() + "_simple.jpg");
        List<SysShopSignageStreet> listSysShopSignageStreet = laoXiMenApiService.getListSysShopSignageStreetByNumber(ss.getSerial_number());
        ss.setListSysShopSignageStreet(listSysShopSignageStreet);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", ss);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 电招电牌列表
     */
    @RequestMapping(value = "/getAllHpDianZhaoDianPaiInfoByStreet")
    public void getAllHpDianZhaoDianPaiInfoByStreet(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllHpDianZhaoDianPaiInfoByStreet-----start-------");

        List<SysShopRecruitStreet> listSysShopRecruitStreet = laoXiMenApiService.getListSysShopRecrutiStreet();

        for (SysShopRecruitStreet ss : listSysShopRecruitStreet) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getLng()), Double.parseDouble(ss.getLat()));
            ss.setLng(map[0] + "");
            ss.setLat(map[1] + "");
//            List<SysShopSignageStreet> listSysShopSignageStreet=laoXiMenApiService.getListSysShopSignageStreetByNumber(ss.getSerial_number());
//            ss.setListSysShopSignageStreet(listSysShopSignageStreet);
        }

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listSysShopRecruitStreet);
        responseData(resultObj.toString(), resp);

    }


    /**
     * 根据街道地址获取经纬度
     */
    @RequestMapping(value = "/operateLngLatByStreetAddress")
    public void operateLngLatByStreetAddress(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        HttpClient client = HttpClientBuilder.create().build();
        List<SysShopRecruitStreet> listSysShopRecruitStreet = laoXiMenApiService.getListSysShopRecrutiStreet();

        JSONArray ja = new JSONArray();
        JSONObject jo = null;
        JSONObject jb = null;
        JSONObject locationjson = null;
        for (SysShopRecruitStreet s : listSysShopRecruitStreet) {


            // 根据URL创建HttpGet实例
            //http://172.82.4.1:8070
            //173.82.57.8:8070
            HttpGet get = new HttpGet("http://api.map.baidu.com/geocoder?address=上海市黄浦区" + s.getUnit_adress() + "&output=json&key=PyLa5E6K6BEGI0euwz1s9dWc&city=上海市");
            // 执行get请求，得到返回体
            HttpResponse response = client.execute(get);
            // 判断是否正常返回
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                // 解析数据
                String data = EntityUtils.toString(response.getEntity(), Charsets.UTF_8);
                jo = JSONObject.parseObject(data);
                if (jo.get("status").equals("OK")) {
                    jb = jo.getJSONObject("result");
                    locationjson = jb.getJSONObject("location");
                    System.out.println(s.getUnit_adress() + "----" + locationjson.getString("lng") + "------" + locationjson.getString("lat"));
                    laoXiMenApiService.updateSysShopRecruitStreetLngLatById(locationjson.getString("lng"), locationjson.getString("lat"), s.getId());
                }
            }
//                        }    sysHpEmergencyEvent.setBaiduLongitude(locationjson.getString("lng"));
//                            sysHpEmergencyEvent.setBaiduLatitude(locationjson.getString("lat"));


        }


    }


    /**
     * 根据电梯地址获取经纬度
     */
    @RequestMapping(value = "/operateLngLatByStreetElevatorAddress")
    public void operateLngLatByStreetElevatorAddress(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        HttpClient client = HttpClientBuilder.create().build();
        List<LxmElevatorInfo> listLxmElevatorInfo = laoXiMenApiService.getListLxmElevatorInfo();
        JSONArray ja = new JSONArray();
        JSONObject jo = null;
        JSONObject jb = null;
        JSONObject locationjson = null;
        for (LxmElevatorInfo s : listLxmElevatorInfo) {

            try {
                // 根据URL创建HttpGet实例
                //http://172.82.4.1:8070
                //173.82.57.8:8070
                HttpGet get = new HttpGet("http://api.map.baidu.com/geocoder?address=上海市黄浦区" + s.getDevice_use_site() + "&output=json&key=PyLa5E6K6BEGI0euwz1s9dWc&city=上海市");
                // 执行get请求，得到返回体
                HttpResponse response = client.execute(get);
                // 判断是否正常返回
                if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    // 解析数据
                    String data = EntityUtils.toString(response.getEntity(), Charsets.UTF_8);
                    jo = JSONObject.parseObject(data);
                    if (jo.get("status").equals("OK")) {
                        jb = jo.getJSONObject("result");
                        locationjson = jb.getJSONObject("location");
                        System.out.println(s.getDevice_use_site() + "----" + locationjson.getString("lng") + "------" + locationjson.getString("lat"));
                        laoXiMenApiService.updateElevatorInfoLngLatById(locationjson.getString("lng"), locationjson.getString("lat"), s.getId());
                    }
                }
            } catch (Exception e) {
                continue;
            }


        }


    }


    /**
     * 获取全区视频信息-老西门街道
     */
    @RequestMapping(value = "/gethpPublicVideoByStreet")
    public void gethpPublicVideoByStreet(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        String str = getRequestBodyString(req);
        JSONObject jsonObject = null;

        LogFactory.getLog(this.getClass()).info("------gethpPublicVideoByStreet-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);

        // 当前页码
        int page = reqjson.getInteger("page");

        List<SysHpPublicVideoStreet> listSysHpPublicVideo = laoXiMenApiService.getRoadIdsFromHpPublicVideoByStreet(page, Constants.GOODSPAGESIZE);


        JSONObject returnjson = new JSONObject();

        List<SysHpPublicVideoStreet> onelevelvideo = laoXiMenApiService.getRoadIdsFromHpPublicVideoByStreetCondition("一类");
        List<SysHpPublicVideoStreet> twolevelvideo = laoXiMenApiService.getRoadIdsFromHpPublicVideoByStreetCondition("二类");
        List<SysHpPublicVideoStreet> threelevelvideo = laoXiMenApiService.getRoadIdsFromHpPublicVideoByStreetCondition("三类");


        List<SysHpPublicVideoStreet> importvideo = laoXiMenApiService.getRoadIdsFromHpPublicVideoByStreetImportCondition();
//        returnjson.put()
        returnjson.put("onelevelvideo", onelevelvideo);
        returnjson.put("twolevelvideo", twolevelvideo);
        returnjson.put("threelevelvideo", threelevelvideo);
        returnjson.put("importvideo", importvideo);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", returnjson);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 隐患列表
     *
     * @return
     */
    @RequestMapping(value = "/getErrorShopList")
    public void getErrorShopList(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getErrorShopList-----start-------");
        JSONObject result = null;
        JSONArray jsonArray = new JSONArray();
        List<LxmShopError> listLxmShopError = laoXiMenApiService.getListShopError();
        for (LxmShopError shop : listLxmShopError) {
            result = new JSONObject();
            result.put("shopid", shop.getId());
            shop.setImageurl("http://172.82.4.51:8080/images/" + shop.getNumber() + ".jpg");
            result.put("address", shop.getAddress());
            result.put("unit_name", shop.getUnit_name() + "");
            LxmSignageError signage = laoXiMenApiService.getLxmSignageError(shop.getNumber());
            result.put("examine_date", signage.getExamine_date());
            result.put("suggest", signage.getSuggest());
            result.put("result", signage.getResult());
            result.put("hidden_danger_desc", signage.getHidden_danger_desc());
            result.put("review_date", signage.getReview_date());
            result.put("review_result", signage.getReview_result() + "");
            result.put("type", signage.getType());
            jsonArray.add(result);
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", jsonArray);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 根据隐患ID获取基本信息
     */
    @RequestMapping(value = "/getErrorShopById")
    public void getErrorShopById(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getErrorShopById-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String shopid = reqjson.getString("shopid");
        LxmShopError shop = laoXiMenApiService.getErrorShopById(shopid);
        List<LxmSignageError> listLxmSignageError = laoXiMenApiService.getListLxmSignageError(shop.getNumber());
        double[] map = MapUtil.bd09towgs84(Double.parseDouble(shop.getX()), Double.parseDouble(shop.getY()));
        shop.setX(map[0] + "");
        shop.setY(map[1] + "");
        shop.setImageurl("http://172.82.4.51:8080/images/" + shop.getNumber() + ".jpg");
        shop.setImageurl1("http://172.82.4.51:8080/images/" + shop.getNumber() + "_simple.jpg");
        if (StringUtil.isNotEmpty(shop.getRectify_number())) {
            shop.setRectifyImageurl("http://172.82.4.51:8080/images/" + shop.getRectify_number() + ".jpg");
            shop.setRectifyImageurl1("http://172.82.4.51:8080/images/" + shop.getRectify_number() + "_simple.jpg");
        }

        JSONObject resultjson = new JSONObject();
        resultjson.put("shop", shop);
        resultjson.put("signageError", listLxmSignageError);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultjson);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 根据隐患店招状态获取相关信息 0 已拆除  1移交城管 2 全部
     */
    @RequestMapping(value = "/getErrorSignageListByType")
    public void getErrorSignageListByType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getErrorSignageListByType-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String type = reqjson.getString("type");
        List<String> listNumber = laoXiMenApiService.getListNumberByType(type);

        List<LxmShopError> listLxmShopError = new ArrayList<LxmShopError>();
        for (String number : listNumber) {
            LxmShopError shop = laoXiMenApiService.getErrorShopByNumber(number);
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(shop.getX()), Double.parseDouble(shop.getY()));
            shop.setType(laoXiMenApiService.getLxmShopTypeByNumber(number));
            shop.setX(map[0] + "");
            shop.setY(map[1] + "");
            listLxmShopError.add(shop);
        }


        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listLxmShopError);
        responseData(resultObj.toString(), resp);
    }


    /**
     * 从req中读取数据
     *
     * @param req
     * @return
     */
    private String getRequestBodyString(HttpServletRequest req) {
        StringBuilder builder = new StringBuilder();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream(), "utf-8"));
            String line;
            while ((line = br.readLine()) != null) {
                builder.append(line);
            }
        } catch (IOException e) {
            // e.printStackTrace();
            return null;
        }
        return builder.toString();
    }

    private void responseErrorData(String string, HttpServletResponse resp) throws Exception {
        // TODO Auto-generated method stub
        JSONObject resultObj = new JSONObject();
        resultObj.put("errorcode", 1);
        resultObj.put("message", string);
        responseData(resultObj.toString(), resp);
    }

    private void responseData(String string, HttpServletResponse resp) throws Exception {
        // TODO Auto-generated method stub
        responseDate("application/json;charset=UTF-8", string, resp);

    }

    private void responseDate(String contentType, String value, HttpServletResponse resp) throws Exception {
        resp.setContentType(contentType);
        resp.getWriter().write(value);
    }
}
